package helipay.api.dao.impl;

import helipay.api.dao.OrdersSwipeCardDao;
import helipay.api.jdbc.StatementParameter;
import helipay.api.model.OrdersSwipeCard;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yimi on 2017/5/5.
 */
@Repository
public class OrdersSwipeCardDaoImpl extends AbstractBaseDao<OrdersSwipeCard> implements OrdersSwipeCardDao {

    @Override
    public List<OrdersSwipeCard> getOrdersListBySwipeCard(String customerNumber, String startDate, String endDate, Integer index) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT ORDER_AMOUNT, SERIAL_NUMBER,CREATED_TIME,STATUS,BIZ_TYPE " +
                "FROM ORDERS_SWIPE_CARD  WHERE CUSTOMER_NUMBER=?  AND CREATED_TIME BETWEEN ? AND ? LIMIT ?,10");

        StatementParameter param = new StatementParameter();
        param.setString(customerNumber);
        param.setString(startDate);
        param.setString(endDate);
        param.setInt(index*10);
        return this.queryForList(sb.toString(),OrdersSwipeCard.class,param);
    }

    @Override
    public Integer getSizeBySwipeCard(String customerNumber, String startDate, String endDate) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT COUNT(ID) " +
                "FROM ORDERS_SWIPE_CARD  WHERE CUSTOMER_NUMBER=?  AND CREATED_TIME BETWEEN ? AND ?");

        StatementParameter param = new StatementParameter();
        param.setString(customerNumber);
        param.setString(startDate);
        param.setString(endDate);
        return this.queryForInt(sb.toString(),param);
    }

    @Override
    public List<OrdersSwipeCard> orderSwipeCardListByCustomerNumber(String customerNumber) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT ORDER_AMOUNT, SERIAL_NUMBER,CREATED_TIME,STATUS,BIZ_TYPE " +
                "FROM ORDERS_SWIPE_CARD  WHERE CUSTOMER_NUMBER=? ");

        StatementParameter param = new StatementParameter();
        param.setString(customerNumber);
        return this.queryForList(sb.toString(),OrdersSwipeCard.class,param);
    }
}
